package com.huawei;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class HJ008 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int maxLine = Integer.valueOf(scanner.nextLine());
        int nowLine = 0;

//        for (int i = 0; i < length; i++) {
//            int key = in.nextInt();
//            int val = in.nextInt();
//        }
        //要对key升序排序
        TreeMap<Integer, Integer> map = new TreeMap<>();
        while(scanner.hasNextLine()){
            String str = scanner.nextLine();

            String[] strArr = str.split(" ");

            Integer key = Integer.valueOf(strArr[0]);
            Integer value = Integer.valueOf(strArr[1]);
            map.put(key,map.getOrDefault(key,0)+value);
            ++ nowLine;
            if(nowLine == maxLine){
                break;
            }
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            Integer key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+" "+value);
        }

    }
}
